package com.bite.book.config;

import com.bite.book.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
    //1. 注入拦截器对象
    @Autowired
    private LoginInterceptor loginInterceptor;
    //2. 重写方法, 配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //addPathPatterns方法, 表示添加拦截的路径  /** 表示全部路径
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/**/*.js")
                .excludePathPatterns("/**/*.css")
                .excludePathPatterns("/**/*.png")
                .excludePathPatterns("/**/*.html")
                .excludePathPatterns("/test/**")
                .excludePathPatterns("/error");

    }
}
